import { _decorator, Component, Node } from 'cc';
import { SingleCat } from './SingleCat';
import { Global } from '../Global';
const { ccclass, property } = _decorator;

@ccclass('CatLoad')
/**
 * 猫咪层
 */
export class CatLoad extends Component {

    //喵咪数组
    @property([Node])
    public CatArr: Node[] = [];

    /**
     * 更新完成得猫咪
     */
    public UpdateClearCat() {
        for (let cat of this.CatArr) {
            if (cat.getComponent(SingleCat).FruitNum <= 0) {
                let fruit: number = Math.floor(Math.random() * Global.SpriteType);
                let f_n: number = 5 + Math.floor(Math.random() * 10);
                cat.getComponent(SingleCat).UpdateFruitNum(f_n, fruit);
            }
        }
    }

    /**
     * 更新数量
     */
    public UpdateCatFruitNum(_num: number, _fruit: number) {
        for (let cat of this.CatArr) {
            if (cat.getComponent(SingleCat).FruitIndex == _fruit) {
                cat.getComponent(SingleCat).CompleteFruit(_num);
                break;
            }
        };

        this.UpdateClearCat();
    }

}


